package ch.bfh.mobicomp.soda2.temperature;

import java.io.Serializable;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.BatteryManager;
import android.util.Log;

//http://developer.android.com/training/monitoring-device-state/battery-monitoring.html
public class BatteryStatusReceiver extends BroadcastReceiver implements Serializable{
	@Override
	public void onReceive(Context context, Intent intent) {
		Log.i(SODATemperatureDataCollectorService.TAG, "Intent received");

		if (intent == null) {
			return;
		}
		Intent serviceIntent = null;
		if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
			Log.i(SODATemperatureDataCollectorService.TAG, intent.getAction());
			serviceIntent = SODATemperatureDataCollectorService.getStartIntent(context,
					System.currentTimeMillis());

		}
//		if (intent.getAction().equals(Intent.ACTION_BATTERY_CHANGED)) {
//			Log.i(SODATemperatureDataCollectorService.TAG, intent.getAction());
//			int temperature = intent.getIntExtra(
//					BatteryManager.EXTRA_TEMPERATURE, 0);
//			Log.i(SODATemperatureDataCollectorService.TAG, "Temperature: " + temperature);
//			serviceIntent = SODATemperatureDataCollectorService.getBatteryTemperatureIntent(
//					context, temperature, System.currentTimeMillis());
//			Log.i(SODATemperatureDataCollectorService.TAG, serviceIntent.getAction());
//		}
		if (serviceIntent != null) {
			{
				Log.i(SODATemperatureDataCollectorService.TAG, "Service started");
				context.startService(serviceIntent);
				Log.i(SODATemperatureDataCollectorService.TAG, "Service finished");

			}
		}
	}
}
